home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Task / c++ / GuiObject < prev    next >
Text File  |  2003-02-14  |  7KB  |  225 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "GuiObject.h"
  39. #include "GuiWindow.h"
  40. #include "swis.h"
  41. #include "gfx.h"
  42. #include "ERROR.h"
  43.  
  44. int GuiObject::getValue(int method_code,int fail_value) const
  45. {
  46.   int result=fail_value;
  47.   _swix(Toolbox_ObjectMiscOp,_INR(0,2) | _OUT(0),0,id(),method_code,&result);
  48.   return result;
  49. }
  50.  
  51. //********************************************************************************
  52.  
  53. bool GuiObject::getValue(int method_code,void* value) const
  54. {
  55.   if (value==NULL) return 0;
  56.   return _swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value)==NULL;
  57. }
  58.  
  59. //********************************************************************************
  60.  
  61. void GuiObject::setValue(int method_code,int value)
  62. {
  63.   _swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value);
  64. }
  65.  
  66. //********************************************************************************
  67.  
  68. void GuiObject::setValue(int method_code,const void* value)
  69. {
  70.   _swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value);
  71. }
  72. //********************************************************************************
  73.  
  74. string GuiObject::getString(int method_code) const
  75. {
  76.   string s;
  77.   _kernel_swi_regs reg;
  78.   reg.r[0]=0;
  79.   reg.r[1]=id();
  80.   reg.r[2]=method_code;
  81.   reg.r[3]=0;
  82.   reg.r[4]=0;
  83.  
  84.   if (_kernel_swi(Toolbox_ObjectMiscOp,®,®)==NULL)
  85.      {
  86.      s.resize(reg.r[4]-1);
  87.      if (s.size()==reg.r[4]-1)
  88.         {
  89.         reg.r[3]=(int)s.data();
  90.         _kernel_swi(Toolbox_ObjectMiscOp,®,®);
  91.         }
  92.      }
  93.   return s;
  94. }
  95.  
  96. //********************************************************************************
  97.  
  98. void GuiObject::setString(int method_code,const char* str)
  99. {
  100.   _swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,str);
  101. }
  102.  
  103. //********************************************************************************
  104.  
  105. GuiObject::GuiObject(const char* name) :m_auto_delete(1)
  106. {
  107.   if (name==0)
  108.   {
  109.     WARN("Error: Attempt to create Object with no name");
  110.   }
  111.   else if (_swix(Toolbox_CreateObject,_INR(0,1)|_OUT(0),0,name,&m_id)!=NULL)
  112.   {
  113.     WARN("Error: Couldn't create %s",name);
  114.     m_id=NULL_GuiObjectId;
  115.   }
  116. }
  117.  
  118. //********************************************************************************
  119.  
  120. GuiObject::GuiObject(GuiObjectId id) : m_id(id),m_auto_delete(0) {}
  121.  
  122. //********************************************************************************
  123.  
  124. GuiObject::~GuiObject()
  125. {
  126.   if (m_auto_delete && id() != NULL_GuiObjectId)
  127.      {
  128.      _swix(Toolbox_DeleteObject,_INR(0,1),0,id());
  129.      }
  130. }
  131.  
  132. //********************************************************************************
  133.  
  134. void GuiObject::show(int flags, int show_type,const void *type,
  135.                    const GuiObject*  parent,
  136.                    GuiComponentId    parent_component_id)
  137. {
  138.   if (id() != NULL_GuiObjectId)
  139.      {
  140.      _swix(Toolbox_ShowObject,_INR(0,5),flags,id(),
  141.                                         show_type,type,
  142.                                         (parent ? parent->id() : NULL_GuiObjectId),
  143.                                         parent_component_id);
  144.      }
  145. };
  146.  
  147. //********************************************************************************
  148.  
  149. void GuiObject::hide()
  150. {
  151.   if (id() != NULL_GuiObjectId)
  152.      {
  153.       _swix(Toolbox_HideObject,_INR(0,1),0,id());
  154.      }
  155. }
  156.  
  157. //********************************************************************************
  158.  
  159. bool GuiObject::isShowing() const
  160. {
  161.   if (id() == NULL_GuiObjectId) return 0;
  162.   unsigned int state;
  163.   return (_swix(Toolbox_GetObjectState,_INR(0,1) | _OUT(0),0,id(),&state)==NULL)?state:0;  
  164. }
  165.  
  166. //********************************************************************************
  167. //********************************************************************************
  168. //********************************************************************************
  169.  
  170. GuiWindowObject::~GuiWindowObject() {}
  171.  
  172. //********************************************************************************
  173.  
  174. void GuiWindowObject::showAtPointer(int flags,
  175.                                       const GuiObject*  parent,
  176.                                       GuiComponentId    parent_component_id,
  177.                                       const GuiTopLeft* offset)
  178. {
  179.   GuiPointerInfo pib;
  180.   GuiGetWindowStateBlock ws;
  181.   GuiWindow(underlyingWindowId()).getState(ws);
  182.  
  183.   pib.x += (offset)?offset->x:-64;
  184.   pib.y += (offset)?offset->y:0;
  185.   ws.visibleArea.moveTo(pib.x,pib.y);
  186.  
  187.   ws.behind=-1;
  188.  
  189.   GuiObject::show(flags,ShowTypeFullSpec,&ws.visibleArea,parent,parent_component_id);
  190. }
  191.  
  192. //********************************************************************************
  193.  
  194. void GuiWindowObject::showCentred(int flags,
  195.                                    int offset_x,int offset_y,
  196.                                    const GuiWindowObject* centre_in_this_window,
  197.                                    const GuiObject*       parent,
  198.                                    GuiComponentId         parent_component_id)
  199. {  
  200.   GuiGetWindowStateBlock bounds;
  201.   if (centre_in_this_window)
  202.   {
  203.      GuiWindow(centre_in_this_window->underlyingWindowId()).getState(bounds);
  204.   }
  205.   else
  206.   {
  207.      bounds.visibleArea.xmin=0;
  208.      bounds.visibleArea.ymin=0;
  209.      bounds.visibleArea.xmax=gfx::screenwidth();
  210.      bounds.visibleArea.ymax=gfx::screenheight();
  211.   }
  212.   
  213.   GuiGetWindowStateBlock ws;
  214.   GuiWindow(underlyingWindowId()).getState(ws);
  215.   ws.visibleArea.centreInBox(bounds.visibleArea);
  216.   ws.visibleArea.moveBy(offset_x,offset_y);
  217.  
  218.   ws.behind=-1;
  219.  
  220.   GuiObject::show(flags,ShowTypeFullSpec,&ws.visibleArea,parent,parent_component_id);
  221. }
  222.  
  223. //********************************************************************************
  224.  
  225.